package com.nd.android.u.ui.longClickMenu.messageList;

import java.util.ArrayList;

import android.content.Context;
import android.text.SpannableString;

import com.common.android.utils.smiley.Smiley;
import com.common.android.utils.smiley.Smileyhelper;
import com.nd.android.u.controller.ChatConst.LocalMessageType;
import com.nd.android.u.controller.ChatConst.MessageContentType;
import com.nd.android.u.controller.MessageConst.ServerMessageType;
import com.nd.android.u.controller.innerInterface.IChatListLongClickMenu;
import com.nd.android.u.controller.innerInterface.IMessageDisplay;
import com.nd.android.u.ui.R;
import com.nd.android.u.ui.beanStarApp.DisplayMessage_Person;
import com.product.android.business.ApplicationVariable;
import com.product.android.business.ProductTypeDef;
import com.product.android.business.config.Configuration;

/**
 * [下单] 菜单项
 * @author yufeng
 * @version 创建时间：2014-7-18 上午10:40:44
 */
public class MenuItemTask implements IChatListLongClickMenu {

    
    private IMessageDisplay mMessage;

    @Override
    public String getLabel() {
        return ApplicationVariable.INSTANCE.applicationContext
                .getString(R.string.context_menu_item_task);
    }

    @Override
    public void onClick(Context context) {
        String text = "";
        switch (mMessage.getMessageContentType()) {
        case MessageContentType.TEXT:
            // 普通消息，传文本
            ArrayList<Object> data = mMessage.getDisplayDatas();
            if (data == null) {
                text = mMessage.getOriMessage();
            } else {
                for (Object object : data) {
                    if (object instanceof String) {
                        text = (String) object;
                        break;
                    } else if (object instanceof SpannableString) {
                    	text=Smileyhelper.getInstance().showSmileyByTip(object.toString(),Smiley.TYPE_CHAT);
                        break;
                    }
                }
            }
            break;
        case ServerMessageType.MSG_APP_XML:          // XXX ImsMessage 常量未转换成MessageState常量
//            text = message.erpInfo.content; // @yf 新MSG对象暂时没有ERPINFO字段
            break;
        case MessageContentType.AUDIO:
        case MessageContentType.OLD_AUDIO:
            text = mMessage.getOriMessage();
            break;
        case MessageContentType.FILE:
        case MessageContentType.OLD_FILE:
            text = mMessage.getOriMessage();
            break;
        default:
            return;
        }
        Object obj=mMessage.getTypeId();
//        if(obj instanceof Long){
//            ChatCallOtherModel.ErpEntry.allocateTask(context, (Long)mMessage.getTypeId(), text);
//        }else{
//           Log.e(Log.CHAT, "getFriendId() is not Long"); 
//        }
    }

    @Override
    public boolean isEnable(IMessageDisplay message) {
    	mMessage=message;
        // 系统消息和应用消息没有弹出菜单, 公众号消息只有"删除"项
        if (mMessage.getMessageType() == LocalMessageType.SYSTEM || mMessage.getMessageType() == LocalMessageType.APP
                || mMessage.getMessageType() == LocalMessageType.PUBLIC_NUMBER) {
            return false;
        }

        // 如果是网龙，有下单功能
        if (Configuration.PRODUCT == ProductTypeDef.Product.PRODUCT_91UND) {
            return mMessage instanceof DisplayMessage_Person;
        } else {
            return false;
        }
    }
}
